import org.apache.commons.lang3.StringUtils;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class LogParsing {

    private static String convertLine(String originalMessage) {
        return String.format(
                "{\"time\": %s, \"level\": \"%s\", \"message\": \"%s\"}\n",
                StringUtils.substringBefore(originalMessage, " "),
                StringUtils.substringBetween(originalMessage, " ", ":"),
                StringUtils.trim(StringUtils.substringAfterLast(originalMessage, ":"))
        );
    }


    public static void main(String[] args) throws IOException {

        String fileName = "log.log";

        InputStream inputStream = LogParsing.class.getResourceAsStream(fileName);
        InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
        BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

        StringBuilder result = new StringBuilder();

        String line;
        while ((line = bufferedReader.readLine()) != null) {
            result.append(convertLine(line));
        }

        System.out.println(result.toString());

        bufferedReader.close();
        inputStreamReader.close();
        inputStream.close();
    }

}
